#pragma once

#include "SendObjectAction.h"

#include "InputPin.h"

namespace uml {

SendObjectAction::SendObjectAction(const QString& umlType)
    : InvocationAction(umlType) {}

void SendObjectAction::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    InvocationAction::fromJson(json, errorList);
    request_ = JsonSerializable::create<InputPin>(json.value("request"), errorList);

    target_ = JsonSerializable::create<InputPin>(json.value("target"), errorList);

}

void SendObjectAction::toJson(QJsonObject& json) {
    InvocationAction::toJson(json);
    if (request_) {
        QJsonObject request_json;
        request_->toJson(request_json);
        json.insert("request", request_json);
    }
    if (target_) {
        QJsonObject target_json;
        target_->toJson(target_json);
        json.insert("target", target_json);
    }
}

/// <summary>
/// request getter
/// The request object, which is transmitted to the target object. The object may be
/// copied in transmission, so identity might not be preserved.
/// </summary>
shared_ptr<InputPin> SendObjectAction::request() const {
    return request_;
}

/// <summary>
/// request setter
/// The request object, which is transmitted to the target object. The object may be
/// copied in transmission, so identity might not be preserved.
/// </summary>
void SendObjectAction::setRequest(shared_ptr<InputPin> value) {
    request_ = value;
}

/// <summary>
/// target getter
/// The target object to which the object is sent.
/// </summary>
shared_ptr<InputPin> SendObjectAction::target() const {
    return target_;
}

/// <summary>
/// target setter
/// The target object to which the object is sent.
/// </summary>
void SendObjectAction::setTarget(shared_ptr<InputPin> value) {
    target_ = value;
}

} // namespace uml
